import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

///全部采购订单
class ProcurementAllOrder extends StatefulWidget {
  @override
  _ProcurementAllOrderState createState() => _ProcurementAllOrderState();
}

class _ProcurementAllOrderState extends State<ProcurementAllOrder> {
  List<String> typeList = ["询价中", "待确认", "待支付", "待发货", "已发货", "待评价", "已完成"];
  int checkIndex = 0; //当前选中
  bool isShow = false; //默认隐藏
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      appBar: customAppBar(context, title: "全部订单"),
      body: SingleChildScrollView(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              width: setWidth(375),
              padding: EdgeInsets.only(
                  left: setWidth(10),
                  right: setWidth(10),
                  top: setWidth(16),
                  bottom: setWidth(16)),
              color: Colors.white,
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Container(
                    child: Text(
                      "订单状态",
                      style: TextStyle(
                          color: Color(0xff323232),
                          fontSize: setSp(16),
                          fontWeight: FontWeight.w600),
                    ),
                  ),
                  SizedBox(
                    height: setWidth(15),
                  ),
                  Container(
                      child: StaggeredGridView.countBuilder(
                        physics: NeverScrollableScrollPhysics(),
                        shrinkWrap: true,
                        crossAxisCount: 4,
                        mainAxisSpacing: setWidth(30),
                        crossAxisSpacing: setWidth(10),
                        staggeredTileBuilder: (i) {
                          return StaggeredTile.fit(1);
                        },
                        itemCount: isShow ? typeList.length : 4,
                        itemBuilder: (context, index) {
                          return GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                urlPush(context, "yuntu://category_list?title=${typeList[index]}&type=$index");

                              },
                              child: _gridItem("100", typeList[index]));
                        },
                      )),
                  GestureDetector(
                    behavior: HitTestBehavior.opaque,
                    onTap: (){
                      setState(() {
                        isShow = !isShow;
                      });
                    },
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Container(
                          child: Text(
                            isShow? "收起":"展开",
                            style: TextStyle(
                                color: Color(0xff989898),
                                fontSize: setSp(15),
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                        SizedBox(
                          width: setWidth(5),
                        ),
                        SizedBox(width: setWidth(15),
                          height: setWidth(10),
                          child: Image.asset(isShow?"assets/images/home_up.png":"assets/images/home_done.png",width: setWidth(15),
                            height: setWidth(10),fit: BoxFit.cover,),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              child: ListView.builder(
                  physics: NeverScrollableScrollPhysics(),
                  shrinkWrap: true,
                  itemCount: typeList.length,
                  itemBuilder: (context, index) {
                    return GestureDetector(
                        behavior: HitTestBehavior.opaque,
                        onTap: () {
                          switch (index) {
                            //询价中
                            case 0:
                              urlPush(context, "yuntu://procurement_enquiry");
                              break;
                            //待确认
                            case 1:
                              urlPush(context, "yuntu://await_confirm");
                              break;
                            //待支付
                            case 2:
                              urlPush(context, "yuntu://await_pay");
                              break;
                            //待收货
                            case 3:
                              urlPush(
                                  context, "yuntu://procurement_await_deliver");
                              break;
                            //已收货
                            case 4:
                              urlPush(context,
                                  "yuntu://procurement_already_deliver");
                              break;
                            //待评价
                            case 5:
                              urlPush(context,
                                  "yuntu://procurement_await_evaluate");
                              break;
                            //已完成
                            case 6:
                              urlPush(context, "yuntu://procurement_done");
                              break;
                          }
                        },
                        child: item(index));
                  }),
            )
          ],
        ),
      ),
    );
  }

  Widget _gridItem(String num, String title) {
    return Container(
      child: Column(
        children: [
          Container(
            child: Text(
              num,
              style: TextStyle(
                  color: Color(0xff323232),
                  fontSize: setSp(24),
                  fontWeight: FontWeight.w600),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ),
          ),
          SizedBox(
            height: setWidth(10),
          ),
          Container(
            child: Text(title,
                style: TextStyle(
                    color: Color(0xff686868),
                    fontSize: setSp(14),)),
          )
        ],
      ),
    );
  }

  Widget item(int index) {
    return Container(
      margin: EdgeInsets.only(
          top: setWidth(10), left: setWidth(10), right: setWidth(10)),
      padding: EdgeInsets.only(
          top: setWidth(20),
          left: setWidth(12),
          right: setWidth(12),
          bottom: setWidth(20)),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(4)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  child: Text(
                    "订单编号：AE9998820031",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Container(
                  child: Text(
                    typeList[index],
                    style: TextStyle(
                        color: Color(0xffFF921A), fontSize: setSp(14)),
                  ),
                )
              ],
            ),
          ),
          SizedBox(
            height: setWidth(16),
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  child: Text(
                    "车辆型号：路虎极光",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Container(
                  child: Text(
                    "2020-11-23 14:02",
                    style: TextStyle(
                        color: Color(0xff989898), fontSize: setSp(12)),
                  ),
                )
              ],
            ),
          ),
          SizedBox(
            height: setWidth(16),
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Container(
                  child: Text(
                    "采购件数：19",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
              ],
            ),
          ),
          SizedBox(
            height: setWidth(29),
          ),
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                Container(
                  child: Text(
                    "共9个供应商报价，已确认(5/12)个订单",
                    style: TextStyle(
                        color: Color(0xff1666F1), fontSize: setSp(15)),
                  ),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
